import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/common/sp_key.dart';
import 'package:flutter_learn_vi/src/utils/sp_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 3/18/21.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class TopicTextModel with ChangeNotifier {
  TextSizeBean _textSizeBean = new TextSizeBean();

  int _currentIndex = 1;

  TextSizeBean get textSizeBean => _textSizeBean;

  void subtractTextSize() {
    if (_currentIndex < -4) {
      _currentIndex++;
    } else {
      _currentIndex--;
    }
    _textSizeBean.titleSize = 16.0 + _currentIndex;
    _textSizeBean.typeSize = 12.0 + _currentIndex;
    _textSizeBean.itemSize = 14.0 + _currentIndex;
    notifyListeners();
    SPUtil.save(spTopicTextKey, _textSizeBean);
  }

  void addTextSize() {
    if (_currentIndex > 5) {
      _currentIndex = 1;
    }
    _currentIndex++;
    _textSizeBean.titleSize = 16.0 + _currentIndex;
    _textSizeBean.typeSize = 12.0 + _currentIndex;
    _textSizeBean.itemSize = 14.0 + _currentIndex;
    SPUtil.save(spTopicTextKey, _textSizeBean);
    notifyListeners();
  }

  void clean() {}

  void init() async {
    Map<String, dynamic> map = await SPUtil.getObject(spTopicTextKey);
    if (map != null) {
      _textSizeBean.titleSize = map["titleSize"];
      _textSizeBean.typeSize = map["typeSize"];
      _textSizeBean.itemSize = map["itemSize"];
    }
  }
}

class TextSizeBean {
  double titleSize = 16;

  //单选题
  double typeSize = 12;

  //选项
  double itemSize = 14;
}
